package yt.demo.appcoresystem.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yt.demo.appcommondb.base.BaseService;
import yt.demo.appcommondb.tools.TreeHelper;
import yt.demo.appcommondb.vo.ConditionVO;
import yt.demo.appcoresystem.entity.SystemDept;
import yt.demo.appcoresystem.mapper.SystemDeptMapper;
import yt.demo.appcoresystem.service.ISystemDeptService;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class SystemDeptService extends BaseService<SystemDept, SystemDeptMapper> implements ISystemDeptService {

    @Autowired
    public SystemDeptService(SystemDeptMapper mapper) {
        super(mapper, SystemDept.class);
    }

    @Override
    protected List<ConditionVO<SystemDept, ?>> whereConditions(SystemDept params) {
        return List.of();
    }

    public List<Long> getSupDeptIds(Long deptId) {
        List<SystemDept> allDept = getList(null, null,null);
        return TreeHelper.getChildrenIds(convertToDeptData(allDept),
                "parentId", "id", deptId, true);
    }

    private static List<Map<String, Object>> convertToDeptData(List<SystemDept> allDept) {
        return allDept.stream()
                .map(BeanUtil::beanToMap)
                .toList();
    }


}
